Add lightweight v2 provider interface starter#5086
Conversation
This commit is a lighterweight v2 provider interface. This is an alternative to what is built in Qiskit#4885. While the model in Qiskit#4885 is a desireable end state it requires a lot of changes all at once for providers and potentially users. Instead this commit brings the core concept from Qiskit#4885 of a cleaner explicitly versioned abstract interface but minimizes the changes to the data model used in v1. Only some small changes are made, mainly that jobs can be sync or async, Backend.run() takes a circuit or schedule, options are set via an Options object at __init__, with set_option(), or as kwargs on run(). In all other places the object models from the v1 provider interface are used. This makes the migration to a versioned interface simpler to start. From there we can continue to evolve the interface as was done in Qiskit#4485, like moving to a target object, reimplementing properties and defaults as versioned objects, etc. Since the differences here are so small this commit brings the basicaer provider over to the v2 provider interface. This can be done with minimal effort to showcase how similar the 2 interfaces are.
…into v2-providers-lite
|
So this is blocked on aqua doing explicit type checking in its quantum instance for a |
In Qiskit/qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit/qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit/qiskit#5086
f9fdc21 to
9ede763
Compare
|
I've removed the basicaer changes that switched the basic aer provider to be the first user of the v2 providers interface. This worksaround the tutorials job failure. I also pushed up qiskit-community/qiskit-aqua#1270 to add support for type checking v2 Backend classes to aqua. After this PR merges we can merge the aqua PR. Then after both terra and aqua release I'll push up a PR migrating basic aer to use the v2 interface (we can also start the migration of aer and ibmq too). |
ajavadia
left a comment
There was a problem hiding this comment.
i'm a little confused by v1 vs. v2 - there's a v2 folder, is the intention that there will be v3, v4, etc. folders in the future? or by v2 you mean "everything that will be versioned from now on"?
also ProviderV1 is under the v2 folder. If the idea is that ProviderV2, ProviderV3, etc. will all be in this folder, then I think this folder is a bit redundant and everything should be under the main provider folder.
| def __init__(self, **kwargs): | ||
| self.data = kwargs if kwargs else {} | ||
|
|
||
| def update_options(self, **fields): |
There was a problem hiding this comment.
is it possible to make them into attributes of Options so updating them looks like backend.options.shots=2000?
There was a problem hiding this comment.
Yeah, @jyu00's suggestion above about using SimpleNamespace should enable that pattern for setting it. I'd still like to keep the method because it has the membership check with a custom exception.
There was a problem hiding this comment.
I think you still need a @options.setter in Backend to do backend.options.shots, since right now _options is the real attribute. Maybe just convert set_options() to a setter?
There was a problem hiding this comment.
I think it should be good in it's current form because there is a @parameter decorator on options. So backend.options will return the Options object and then .shots = will call setattr on that object. If we added a setter on options to Backend it would be called when Backend.options =. I do think I should try to figure out if there is a way to add a __setattr__ method to this class to call update_options since right now you could call Backend.options.secret_shots = 10 and that would get set even though its probably not a valid option. But, maybe that's not a problem
| For v1 providers migrating to this first version of a v2 | ||
| provider interface a :class:`~qiskit.qobj.QasmQobj` or | ||
| :class:`~qiskit.qobj.PulseQobj` object. These will be |
There was a problem hiding this comment.
this sentence seems incomplete
There was a problem hiding this comment.
do you mean a QasmQobj and PulseQobj will be supported for now? but the type in docstring doesn't say that
There was a problem hiding this comment.
Oops yeah I missed that. I'll fix it now.
I didn't want to put Qobj in the docstring type because I didn't want to encourage its use for new providers. But, I still wanted to call out anyone migrating from v1 to v2 should probably still support Qobj (but deprecate it) objects for backwards compatibility reasons.
There was a problem hiding this comment.
I updated it here: 523fba9 hopefully it makes more sense now
In Qiskit/qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit/qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit/qiskit#5086
* Add support for v2 provider interface In Qiskit/qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit/qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit/qiskit#5086 * Fix import path * fix style Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
Since Qiskit/qiskit#5086 merged the aer CI jobs have been failing. It looks like it's because pylint can't find the pybind modules. I'm not sure how Qiskit/qiskit#5086 changed things, but this commit tries to fix it by installing aer in the pylint job.
Qiskit/qiskit#5086 seemd to break pylint testing by preventing the Aer package from being found by pylint without building and installing. This fixes the issue by replacing all absolute imports in Aer with relative module imports. This is a work around until general namespace packaging issues are implemented to move all of Aer into its own namespace.
Qiskit/qiskit#5086 seemd to break pylint testing by preventing the Aer package from being found by pylint without building and installing. This fixes the issue by replacing all absolute imports in Aer with relative module imports. This is a work around until general namespace packaging issues are implemented to move all of Aer into its own namespace.
) * Add support for v2 provider interface In Qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit#5086 * Fix import path * fix style Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
) * Add support for v2 provider interface In Qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit#5086 * Fix import path * fix style Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
) * Add support for v2 provider interface In Qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit#5086 * Fix import path * fix style Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
) * Add support for v2 provider interface In Qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit#5086 * Fix import path * fix style Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
) * Add support for v2 provider interface In Qiskit/qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit/qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit/qiskit#5086 * Fix import path * fix style Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
) * Add support for v2 provider interface In Qiskit/qiskit#5086 the v2 provider interface is being added. This starter interface is basically a drop in replacement for the v1 interface with 3 changes it's explicitly versioned at the object level, Backend.run() can take in a circuit object, and Job objects can also be async or sync. Eventually the interace will likely evolve towards a model similar to what was initially done in Qiskit/qiskit#4885. This commit adds initial support for v2 provider backend objects, the explicit type checking for BaseBackend objects is blocking the terra PR from moving forward (because it switched BasicAer to use the v2 interface). This initial support just means accepting v2 Backend objects in addition to v1 BaseBackend objects. Depends on Qiskit/qiskit#5086 * Fix import path * fix style Co-authored-by: Manoel Marques <manoel.marques@ibm.com>
* Add lightweight v2 provider interface starter This commit is a lighterweight v2 provider interface. This is an alternative to what is built in #4885. While the model in #4885 is a desireable end state it requires a lot of changes all at once for providers and potentially users. Instead this commit brings the core concept from #4885 of a cleaner explicitly versioned abstract interface but minimizes the changes to the data model used in v1. Only some small changes are made, mainly that jobs can be sync or async, Backend.run() takes a circuit or schedule, options are set via an Options object at __init__, with set_option(), or as kwargs on run(). In all other places the object models from the v1 provider interface are used. This makes the migration to a versioned interface simpler to start. From there we can continue to evolve the interface as was done in #4485, like moving to a target object, reimplementing properties and defaults as versioned objects, etc. Since the differences here are so small this commit brings the basicaer provider over to the v2 provider interface. This can be done with minimal effort to showcase how similar the 2 interfaces are. * Fix basicaer simulator init * Fix lint * Add provider property to basicaer for Aqua backwards compat * Add provider method back to backend class for backwards compat * Fix lint * Add release notes * Add v2 provider to docs * Fix lint * Revert basicaer v2 provider migration * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com> * Add missing version attributes * Make Options a simplenamespace subclass * Update Backend docstrings * Add v2 Backend support to the rest of terra * Fix lint * Fix lint * Flatten providers subpackage * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Update release notes * Migrate basic aer provider to v2 interface This commit migrates the basic aer provider to the v2 interface. This was originally included in #5086 but had to be removed because of a potential backwards compatibility issue with aqua when using basic aer as the provider (aqua 0.7.x explicity checks for v1 interface backends). * DNM install aqua from source to test tutorials * Remove deprecated schema validation * Test failures * Fix tests and lint * Install aqua from source until release * Add release notes * Add ignis from source too as a dependency of aqua * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Finish upgrade release note Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>
…5128) * Add lightweight v2 provider interface starter This commit is a lighterweight v2 provider interface. This is an alternative to what is built in Qiskit/qiskit#4885. While the model in Qiskit/qiskit#4885 is a desireable end state it requires a lot of changes all at once for providers and potentially users. Instead this commit brings the core concept from Qiskit/qiskit#4885 of a cleaner explicitly versioned abstract interface but minimizes the changes to the data model used in v1. Only some small changes are made, mainly that jobs can be sync or async, Backend.run() takes a circuit or schedule, options are set via an Options object at __init__, with set_option(), or as kwargs on run(). In all other places the object models from the v1 provider interface are used. This makes the migration to a versioned interface simpler to start. From there we can continue to evolve the interface as was done in Qiskit/qiskit#4485, like moving to a target object, reimplementing properties and defaults as versioned objects, etc. Since the differences here are so small this commit brings the basicaer provider over to the v2 provider interface. This can be done with minimal effort to showcase how similar the 2 interfaces are. * Fix basicaer simulator init * Fix lint * Add provider property to basicaer for Aqua backwards compat * Add provider method back to backend class for backwards compat * Fix lint * Add release notes * Add v2 provider to docs * Fix lint * Revert basicaer v2 provider migration * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com> * Add missing version attributes * Make Options a simplenamespace subclass * Update Backend docstrings * Add v2 Backend support to the rest of terra * Fix lint * Fix lint * Flatten providers subpackage * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Update release notes * Migrate basic aer provider to v2 interface This commit migrates the basic aer provider to the v2 interface. This was originally included in Qiskit/qiskit#5086 but had to be removed because of a potential backwards compatibility issue with aqua when using basic aer as the provider (aqua 0.7.x explicity checks for v1 interface backends). * DNM install aqua from source to test tutorials * Remove deprecated schema validation * Test failures * Fix tests and lint * Install aqua from source until release * Add release notes * Add ignis from source too as a dependency of aqua * Apply suggestions from code review Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> * Finish upgrade release note Co-authored-by: Ali Javadi-Abhari <ajavadia@users.noreply.github.com> Co-authored-by: Jessie Yu <jessieyu@us.ibm.com>
Summary
This commit is a lighterweight v2 provider interface. This is an
alternative to what is built in #4885. While the model in #4885 is a
desireable end state it requires a lot of changes all at once for
providers and potentially users. Instead this commit brings the core
concept from #4885 of a cleaner explicitly versioned abstract interface
but minimizes the changes to the data model used in v1. Only some small
changes are made, mainly that jobs can be sync or async, Backend.run()
takes a circuit or schedule, options are set via an Options object at
init, with set_option(), or as kwargs on run(). In all other places
the object models from the v1 provider interface are used. This makes
the migration to a versioned interface simpler to start. From there we
can continue to evolve the interface as was done in #4485, like moving
to a target object, reimplementing properties and defaults as versioned
objects, etc.
Since the differences here are so small this commit brings the basicaer
provider over to the v2 provider interface. This can be done with
minimal effort to showcase how similar the 2 interfaces are.
Details and comments